<template>
  <div id="load">
    <div class="showLoading">
      <van-loading type="spinner" color="#1989fa" size="50px" />
    </div>
  </div>
</template>

<script>
import { testIsFriend } from '@/api/my.js'
export default {
    data(){
        return{
            userInfo:{
              name:'',
              phone:'',
              userId:''
            }
        }
    },
    created(){
        this.userInfo.name = !this.getParam("name") ? "" : decodeURIComponent(this.getParam("name"))
        this.userInfo.phone = !this.getParam("phone") ? "" : decodeURIComponent(this.getParam("phone"))
        this.userInfo.userId = !this.getParam("userId") ? "" : this.getParam("userId")
        this.checkRelationship()
    },
    methods:{
      getParam(name) {
            if (window.location.hash.indexOf("?") != -1) {
                    const query = window.location.hash.split("?")[1];
                    const vars = query.split("&");
                    for (var i = 0; i < vars.length; i++) {
                    var pair = vars[i].split("=");
                    if (pair[0] == name) {
                        return pair[1];
                    }
                    }
                } else {
                    return "";
            }

        },
        checkRelationship(){
          console.log(this.userInfo)
          const data = {
            friendUserId:this.userInfo.userId
          }
           testIsFriend(data).then((res) => {
            console.log(res.data,'111111111111111')
            if (res.data.isFriend || res.data.isRelative) {
              const userInfo = {
                name: this.userInfo.name,
                phone: this.userInfo.phone,
                friendUserId: this.userInfo.userId,
                isRelative: res.data.isRelative ? 1 : 0,
                // isFriend: res.data.isFriend ? 1 : 0
              }
              this.$router.push({
                    path: "/isFriend",
                    query: userInfo
                   
              })
            }else{
               this.$router.push({
                    path: "/addFrendOrRelatives",
                    query: this.userInfo
                 })
            }
                
           }).catch(()=>{

           })
            // setTimeout(() => {
            //     this.$router.push({
            //         path: "/addFrendOrRelatives",
            //         query: this.userInfo
            //     })
            // }, 3000);
        }
    }
}
</script>

<style lang="less" scoped>
#load{
   min-width: 375px;
   display: flex;
   justify-content: center;
  .showLoading {
    height: 100vh;
    .van-loading{
         margin: 200px auto;
    }
  } 
}
</style>